#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2,re,os,cookielib,xbmc,imp
path=xbmc.translatePath(os.path.join(os.path.normpath(os.path.join(os.getcwd(),os.pardir,os.pardir)),'hoster'+os.sep+'oracle3'+os.sep+'_youtubedl.py'))
_youtubedl=imp.load_source("_youtubedl", "_youtubedl.py", open(path,'r'))
import _youtubedl

#author:
#elypter
#-mail:elypter@yahoo.de
#version: 0.2
#date: 290610

def check(url):
	if url.rfind("youtube"): 
		return 1
	else:
		return 0

def get_regexp():
	return "(http://(?:www\.)?youtube\.com/watch\?v=[0-9a-zA-Z_-]*)"
def get_name():
	return "youtube"
def join(id):
	return id

def get_data1(url):
	status,link,image,title,filename,captcha,hoster=get_link1(url)
	#print image+"--"+title+"--"+filename+"--"+captcha+"--"+hoster
	result =[]
	#type,name,...content(type=link)=status,link,image,title,filename,quality,uniqid...
	result.append(("link",get_name(),status,link,image,title,filename,"?","1"))
	return result
	
def get_link1(url):
	
	youtube_ie = _youtubedl.YoutubeIE()
	print "exec: "+url
	extr=youtube_ie.extract(url)
	print "extraction: " + str(extr)
	
	if extr != None and extr!="" and len(extr)>0:
		return ("got",extr['url'],extr['thumbnail'],extr['title'],extr['id'],'','youtube')
	else:
		return ("fail",'','','','','','archive')
	
	
def get_link2(param,code):
		return ("got",param,'','','','','youtube')
